package com.ssextjs.data;

import java.sql.Connection;
import java.sql.ResultSet;
import java.util.List;
import java.util.Map;

public class Store {
	public List data;
	public Map baseParams;
	public DataReader reader;
	public DataProxy proxy;
	private List records;
	private String DataUrl="#";
	private String AjaxDataUrl="#";
	
	public ResultSet rs_temp;
	
	public Store(Map opt) {
		this.reader = (DataReader) opt.get("reader");
		if (!opt.containsKey("proxy")) {
			if (opt.containsKey("sql")) {
				proxy = new SqlProxy(this,(String) opt.get("sql"));
				if (this.reader==null) {
					this.reader = new SqlReader();
				}
			}
		}else{
			this.proxy = (DataProxy) opt.get("proxy");
		}
	}
	
	public void load() {
		proxy.load();
	}
	
	public Store setDataUrl(String url) {
		this.DataUrl=url;
		return this;
	}
	
	public String getAjaxDataUrl() {
		return this.AjaxDataUrl;
	}
	
	public Store setAjaxDataUrl(String url) {
		this.AjaxDataUrl=url;
		return this;
	}
	
	public String getDataUrl() {
		return this.DataUrl;
	}
	
	public Connection load(Connection con) {
		if (con!=null) {
			return ((SqlProxy) proxy).load(con);
		}
		return null;
	}
	
	public void setRecords(List recs) {
		this.records = recs;
	}
	public List getRows() {
		return this.records;
	}
}
